package com.yifi.system.service;

import java.util.Date;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.yifi.common.utils.DateUtils;

/** 
* @ClassName: OrgInfoService 
* @Description: TODO
* @author 姚善利
* @date 2021-12-31 10:03:43 
*  
*/
public class OrgInfoService {

	/**
	 * 
	 * @param c_pro
	 * @return	-1表示错误，0表示禁用，1表示正常使用，		//2表示永久使用
	 */
	public ReturnOrg checkOrg(String c_pro)
	{
		ReturnOrg ro=new ReturnOrg();
		String sql="select * from org_info where ccode='"+c_pro+"'";
		Record record=Db.findFirst(sql);
		if(record==null)
		{
			ro.setCode(-1);
			ro.setMsg("当前账号产权出错！");
			return ro;
		}
		else
		{
			String cflag=record.getStr("cflag");
			if(cflag.equals("0"))
			{
				ro.setCode(0);
				ro.setMsg("账号被禁用，请联系管理人员！");
				return ro;
			}
			else if(cflag.equals("1"))
			{
				Date sdate=record.getDate("limitstart");
				Date edate=record.getDate("limitend");
				Date now=DateUtils.getNowDate();
				
				long sdatelong=sdate.getTime();
				long edatelong=edate.getTime();
				long nowlong=now.getTime();
				
				if(nowlong>=sdatelong&&nowlong<=edatelong)
				{
					ro.setCode(1);
					ro.setMsg("正常！");
					return ro;
				}
				else if(nowlong<=sdatelong)
				{
					ro.setCode(0);
					ro.setMsg("账号权限未开始，请联系管理人员！");
					return ro;
				}
				else if(nowlong>=edatelong)
				{
					ro.setCode(0);
					ro.setMsg("账号已到期，请联系管理人员！");
					return ro;
				}
				else 
				{
					ro.setCode(1);
					ro.setMsg("正常！");
					return ro;
				}
			}
			else
			{
				//正常使用
				ro.setCode(1);
				ro.setMsg("正常！");
				return ro;
			}
		}
		
	}
	
	public class ReturnOrg{
		int code;
		String msg;
		/**
		 * @return the code
		 */
		public int getCode() {
			return code;
		}
		/**
		 * @param code the code to set
		 */
		public void setCode(int code) {
			this.code = code;
		}
		/**
		 * @return the msg
		 */
		public String getMsg() {
			return msg;
		}
		/**
		 * @param msg the msg to set
		 */
		public void setMsg(String msg) {
			this.msg = msg;
		}
		
	}
}
